{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#51CTO课程频道：http://edu.51cto.com/lecturer/index/user_id-12330098.html\n",
    "#优酷频道：http://i.youku.com/sdxxqbf\n",
    "#微信公众号：深度学习与神经网络\n",
    "#Github：https://github.com/Qinbf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[21.0, 7.0]\n"
     ]
    }
   ],
   "source": [
    "#Fetch：可以在session中同时计算多个op\n",
    "#定义三个常量\n",
    "input1 = tf.constant(3.0)\n",
    "input2 = tf.constant(2.0)\n",
    "input3 = tf.constant(5.0)\n",
    "#定义一个加法op\n",
    "add = tf.add(input2,input3)\n",
    "#定义一个乘法op\n",
    "mul = tf.multiply(input1,add)\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    #同时执行乘法op和加法op\n",
    "    result = sess.run([mul,add])\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 16.]\n"
     ]
    }
   ],
   "source": [
    "#Feed：先定义占位符，等需要的时候再传入数据\n",
    "#创建占位符\n",
    "input1 = tf.placeholder(tf.float32)\n",
    "input2 = tf.placeholder(tf.float32)\n",
    "#定义乘法op\n",
    "output = tf.multiply(input1,input2)\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    #feed的数据以字典的形式传入\n",
    "    print(sess.run(output,feed_dict={input1:[8.],input2:[2.]}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
